package com.imooc.spark.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * 考虑到旧版本的API报过时警告，所以这里采用kafka 新版本的 API
 */
public class new_Kafka_ProducerApp {

    public static void main(String[] args) {
        Properties properties =  new Properties();

        //指定连接的kafka集群
        properties.put("bootstrap.servers","192.168.19.159:9092");

        //ack
        properties.put("acks","1");

        //序列化
        properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");

        //创建
        KafkaProducer<String,String> producer = new KafkaProducer(properties);


            producer.send(new ProducerRecord<String, String>("bq","步琦我的女神啊~ 爱你~  超级想你~"));



        //关闭资源
        producer.close();


    }
}
